package com.ruoyi.petrol.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.petrol.domain.ChePetrol;
import com.ruoyi.petrol.service.IChePetrolService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 加油站管理Controller
 * 
 * @author ruoyi
 * @date 2024-06-05
 */
@RestController
@RequestMapping("/petrol")
@CrossOrigin
//-------------------
public class ChePetrolController extends BaseController
{
    @Autowired
    private IChePetrolService chePetrolService;

    /**
     * 查询加油站管理列表
     */
//    @RequiresPermissions("petrol:petrol:list")

    @GetMapping("/list")
    public TableDataInfo list(ChePetrol chePetrol)
    {
        startPage();
        List<ChePetrol> list = chePetrolService.selectChePetrolList(chePetrol);
        return getDataTable(list);
    }

    /**
     * 导出加油站管理列表
     */
    @RequiresPermissions("petrol:petrol:export")
    @Log(title = "加油站管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChePetrol chePetrol)
    {
        List<ChePetrol> list = chePetrolService.selectChePetrolList(chePetrol);
        ExcelUtil<ChePetrol> util = new ExcelUtil<ChePetrol>(ChePetrol.class);
        util.exportExcel(response, list, "加油站管理数据");
    }

    /**
     * 获取加油站管理详细信息
     */
//    @RequiresPermissions("petrol:petrol:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(chePetrolService.selectChePetrolById(id));
    }

    /**
     * 新增加油站管理
     */
    @RequiresPermissions("petrol:petrol:add")
    @Log(title = "加油站管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChePetrol chePetrol)
    {
        System.out.println(chePetrol);
        return toAjax(chePetrolService.insertChePetrol(chePetrol));
    }

    /**
     * 修改加油站管理
     */
    @RequiresPermissions("petrol:petrol:edit")
    @Log(title = "加油站管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChePetrol chePetrol)
    {
        return toAjax(chePetrolService.updateChePetrol(chePetrol));
    }

    /**
     * 删除加油站管理
     */
    @RequiresPermissions("petrol:petrol:remove")
    @Log(title = "加油站管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(chePetrolService.deleteChePetrolByIds(ids));
    }
}
